package com.eva.databuilder.builders.cms;

import com.eva.cms.biz.search.DefaultSearchBiz;
import com.eva.cms.biz.search.vo.SearchResultVO;
import com.eva.databuilder.builders.AbstractTemplateDataBuilder;
import com.eva.databuilder.bo.TemplateDataParameters;
import com.eva.framework.common.model.PageWrap;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 构建站内分页搜索数据
 */
@Component
public class SearchPageBuilder extends AbstractTemplateDataBuilder<SearchResultVO> {

    private static final String PARAMETER_KEYWORD = "keyword";

    private static final String PARAMETER_PAGE = "page";

    private static final String PARAMETER_CAPACITY = "capacity";

    @Resource
    private DefaultSearchBiz defaultSearchBiz;

    @Override
    public SearchResultVO build(TemplateDataParameters parameters) {
        PageWrap<String> pageWrap = new PageWrap<>();
        pageWrap.setPage(parameters.getInteger(PARAMETER_PAGE, 1));
        pageWrap.setCapacity(parameters.getInteger(PARAMETER_CAPACITY, 10));
        pageWrap.setModel(parameters.getString(PARAMETER_KEYWORD, ""));
        return defaultSearchBiz.search(pageWrap);
    }
}
